package com.cmos.um.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cmos.um.utils.exception.ExceptionEnum;

import java.util.*;

public class ResultUtil {


    /**
     * 满意度返回数据格式
     * @param rtnMsg
     * @return
     */
    public static Result success (String rtnCode,String rtnMsg,Object object){
        Result result = new Result();
        result.setRtnCode(rtnCode);
        result.setRtnMSg(rtnMsg);
        result.setBean(new HashMap<>());
        result.setBeans(new ArrayList<>());
        result.setObject(object);
        return result;
    }

    public static Result success (String rtnCode,String rtnMsg){
        Result result = new Result();
        result.setRtnCode(rtnCode);
        result.setRtnMSg(rtnMsg);
        result.setBean(new HashMap<>());
        result.setBeans(new ArrayList<>());
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode","0");
        object.put("rtnMsg","成功");
        result.setObject(object);
        return result;
    }
    /**
     *
     * @param exceptionEnum
     * @return
     */
    public static Result success (ExceptionEnum exceptionEnum){
        Result result = new Result();
        result.setRtnCode(exceptionEnum.getCode());
        result.setRtnMSg(exceptionEnum.getMsg());
        result.setBean(new HashMap<>());
        result.setBeans(new ArrayList<>());
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode","0");
        object.put("rtnMsg","成功");
        result.setObject(object);
        return result;
    }
    public static Result success (JSONArray beans){
        Result result = new Result();
        result.setRtnCode("0");
        result.setRtnMSg("成功");
        result.setBean(new HashMap<>());
        result.setBeans(beans);
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode","0");
        object.put("rtnMsg","成功");
        result.setObject(object);
        return result;
    }

    public static Result success(JSONArray beans, ExceptionEnum exceptionEnum){
        Result result = new Result();
        result.setRtnCode("0");
        result.setRtnMSg("成功");
        result.setBeans(beans);
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode",exceptionEnum.getCode());
        object.put("rtnMsg",exceptionEnum.getMsg());
        result.setObject(object);
        return result;
    }


    /**
     * 错误返回
     * @param code
     * @param msg
     * @return
     */
    public static Result error (String code,String msg){
        Result result = new Result();
        result.setRtnCode(code);
        result.setRtnMSg(msg);
        result.setBean(new HashMap());
        result.setBeans(new ArrayList<>());
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode","0");
        object.put("rtnMsg","成功");
        result.setObject(object);
        return result;
    }

    /**
     *
     * @param exceptionEnum
     * @return
     */
    public static Result error (ExceptionEnum exceptionEnum){
        Result result = new Result();
        result.setRtnCode(exceptionEnum.getCode());
        result.setRtnMSg(exceptionEnum.getMsg());
        result.setBean(new HashMap());
        result.setBeans(new ArrayList<>());
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode","0");
        object.put("rtnMsg","成功");
        result.setObject(object);
        return result;
    }

    /**
     * ngcs返回格式
     * @param RtnMsg
     * @return
     */
    public static Result ngcsSuccess (String RtnMsg,Map<String,Object> bean){
        Result result = new Result();
        result.setRtnCode("0");
        result.setRtnMSg(RtnMsg);
        result.setBean(bean);
        return result;
    }

    /**
     * ngcs返回格式
     * @param RtnMsg
     * @return
     */
    public static Result ngcsError (String RtnMsg){
        Result result = new Result();
        result.setRtnCode("0");
        result.setRtnMSg("成功");
        result.setBean(new JSONObject());
        JSONObject object = new JSONObject();
        object.put("rtnCode","-9999");
        object.put("rtnMsg",RtnMsg);
        result.setObject(object);
        return result;
    }

    /**
     * 返回异常信息，在已知的范围内
     * @param exceptionEnum
     * @return
     */
    public static Result exceptionError (ExceptionEnum exceptionEnum){
        Result result = new Result();
        result.setRtnCode("0");
        result.setRtnMSg("成功");
        Map<String,Object> object = new LinkedHashMap<>();
        object.put("rtnCode",exceptionEnum.getCode());
        object.put("rtnMsg",exceptionEnum.getMsg());
        result.setObject(object);
        return result;
    }

}
